 .ONESHELL:

python := python3

package_dir := app

code_dir := $(package_dir)


define setup_env
    $(eval ENV_FILE := $(1))
    @echo " - setup env $(ENV_FILE)"
    $(eval include $(1))
    $(eval export)
endef

.PHONY: reformat
reformat:
	black $(package_dir)
	isort $(package_dir) --profile black --filter-files

.PHONY: prepare-volumes
prepare-volumes:
	$(call setup_env, .env)
	bash prepare_volumes.sh

.PHONY: dev-docker
dev-docker:
	docker compose -f=docker-compose-dev.yml --env-file=.env.dev up

.PHONY: dev-alembic
dev-alembic:
	$(call setup_env, .env)
	alembic -c alembic.ini  upgrade head

.PHONY: dev-bot
dev-bot:
	$(call setup_env, .env.dev)
	python3 -m app.bot

.PHONY: dev-admin
dev-admin:
	$(call setup_env, .env)
	gunicorn app.server.wsgi:app --workers=4 --threads=4 --preload -b 0.0.0.0:5000
	
	
.PHONY: test-docker
test-docker:
	docker compose -f=docker-compose-test.yml --env-file=.env.test up

.PHONY: prod
prod:
	docker compose -f=docker-compose.yml --env-file=.env up -d
